<!-- 横向布局 -->
<template>
	<el-container class="layout">
		<el-header>
			<div class="logo flex pl-4 items-end pr-10">
				<img :src="sysLogo()" alt="logo" />
				<span>{{ sysTitle() }}</span>
			</div>
			<el-menu mode="horizontal" :default-active="activeMenu" :router="false" :unique-opened="true" text-color="#000">
				<!-- 只有在这里写 submenu 才能触发 menu 三个点省略 -->
				<template v-for="subItem in menuList" :key="subItem.path">
					<el-sub-menu v-if="subItem.children?.length" :index="subItem.path" :key="subItem.path + 'el-sub-menu'">
						<template #title>
							<i :class="`iconfont ${subItem.meta.icon || 'iconlayout'} pr-1`"></i>
							<span>{{ subItem.meta.title }}</span>
						</template>
						<SubMenu :menuList="subItem.children" />
					</el-sub-menu>
					<el-menu-item v-else :index="subItem.path" :key="subItem.path + 'el-menu-item'" @click="handleClickMenu(subItem)">
						<i :class="`iconfont ${subItem.meta.icon || 'iconlayout'} pr-1`"></i>
						<template #title>
							<span>{{ subItem.meta.title }}</span>
						</template>
					</el-menu-item>
				</template>
			</el-menu>
			<ToolBarRight />
		</el-header>
		<Main />
	</el-container>
</template>

<script setup lang="ts" name="layoutTransverse">
import { computed, ComputedRef } from "vue";
import { AuthStore } from "@/stores/modules/auth";
import { useRoute, useRouter } from "vue-router";
import { sysTitle, sysLogo } from "@/hooks/useSystem";
import Main from "@/layouts/components/Main/index.vue";
import ToolBarRight from "@/layouts/components/Header/ToolBarRight.vue";
import SubMenu from "@/layouts/components/Menu/SubMenu.vue";

const route = useRoute();
const router = useRouter();
const authStore = AuthStore();
const activeMenu: ComputedRef = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path));
const menuList = computed(() => authStore.showMenuListGet);
const handleClickMenu = (subItem: Menu.MenuOptions) => {
	if (subItem.meta.isLink) return window.open(subItem.meta.isLink, "_blank");
	router.push(subItem.path);
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
